﻿using Application.AppService.IConfig.Dto.Config_file_second_kind;
using AutoMapper;
using Domain.Entity.Config;
using Domain.Repository.IConfig;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CFSKController : Controller
    {
        private readonly IConfig_file_second_kindAppService cFSKAppService;
        private readonly IMapper mapper;

        public CFSKController(IConfig_file_second_kindAppService cFSKAppService, IMapper mapper)
        {
            this.cFSKAppService = cFSKAppService;
            this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }
        public async Task<IActionResult> AddCFSK(Config_file_second_kindAddDto addDto)
        {
            Config_file_second_kind cFSK = mapper.Map<Config_file_second_kind>(addDto);
            int i = await cFSKAppService.AddCFKAsync(cFSK);
            return Json(i);
        }

        public async Task<IActionResult> UpdateCFSK(Config_file_second_kindUpdateDto cFSKUpdateDto)
        {
            Config_file_second_kind cFSK = mapper.Map<Config_file_second_kind>(cFSKUpdateDto);
            int i = await cFSKAppService.UpdateCFKAsync(cFSK);
            return Json(i);
        }


        [HttpPost("GetCFSK")]
        public async Task<IActionResult> GetCFSK()
        {
            List<Config_file_second_kind> cFSKs = await cFSKAppService.GetCFSKAsync();
            return Json(cFSKs);

        }


        [HttpGet("GetCFSKById/{ffid}")]
        public async Task<IActionResult> GetCFSKById(string ffid)
        {
            List<Config_file_second_kind> cFSKss = await cFSKAppService.GetCFSKAsyncById(ffid);
            return Json(cFSKss);
        }

        public async Task<IActionResult> DeleteCFSK(int id)
        {
            int i = await cFSKAppService.DeleteCFKAsync(id);
            return Json(i);
        }
    }
}
